package com.example.administrator.printoutindemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.bean.ChukuListBean;

import java.util.List;

/**
 * Created by noc on 2018/10/24.
 */

public class ChukuListAdapter extends BaseAdapter {

    Context context;
    List<ChukuListBean> list;
    LayoutInflater inflater;

    public ChukuListAdapter(Context context, List<ChukuListBean> list) {
        this.context = context;
        this.list = list;
        this.inflater=LayoutInflater.from(context);

    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            view=getInflater().inflate(R.layout.cklistitem,null);
            holder=new ViewHolder();
            holder.tv_wlmc=view.findViewById(R.id.tv_wlmc);
            holder.tv_xmmc=view.findViewById(R.id.tv_xmmc);
            holder.tv_sl=view.findViewById(R.id.tv_sl);
            holder.ll_tiaomu=view.findViewById(R.id.ll_tiaomu);

        }
        if (list.get(i).getMaterial()!=null){
            holder.tv_wlmc.setText(list.get(i).getMaterial());
        }
        if (list.get(i).getProjectname()!=null){
            holder.tv_xmmc.setText(list.get(i).getProjectname());
        }
        if (String.valueOf(list.get(i).getReal_count())!=null){
            holder.tv_sl.setText(String.valueOf(list.get(i).getReal_count()));
        }
        return view;
    }
    class ViewHolder{
        TextView tv_wlmc,tv_xmmc,tv_sl;
        LinearLayout ll_tiaomu;

    }
    public void addAll(List<ChukuListBean> chukuListBeen){
        list.addAll(chukuListBeen);
        notifyDataSetChanged();
    }
}
